package com.example.g7640.controller;


import com.example.g7640.builder.ResultBuilder;
import com.example.g7640.dto.AdminDto;
import com.example.g7640.dto.common.Result;
import com.example.g7640.entity.Administrator;
import com.example.g7640.service.AdministratorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/api/admin")
public class AdministratorController {

    @Resource
    AdministratorService administratorService;

    @PostMapping("add")
    public Result<Boolean> add(@RequestBody Administrator administrator) {
        return ResultBuilder.buildSuccess(administratorService.add(administrator));
    }

    @PostMapping("del")
    public Result<Boolean> del(@RequestBody Administrator administrator) {
        return ResultBuilder.buildSuccess(administratorService.removeById(administrator));
    }

    @PostMapping("set-password")
    public Result<Boolean> setPassword(@RequestBody Administrator administrator){
        return ResultBuilder.buildSuccess(administratorService.setPassword(administrator));
    }

    @PostMapping("set-name")
    public Result<Boolean> setName(@RequestBody Administrator administrator){
        return ResultBuilder.buildSuccess(administratorService.setName(administrator));
    }

    @PostMapping("get-list")
    public Result<List<AdminDto>> getList() {
        return ResultBuilder.buildSuccess(administratorService.getList());
    }

    @PostMapping("get-info")
    public Result<Administrator> getInfo(@RequestBody Administrator administrator){
        return ResultBuilder.buildSuccess(administratorService.getInfo(administrator));
    }
}
